<div class="content-wrapper">
    <?php
    $form = $this->form;
    $form->prepare();
    ?>
    <?php echo $this->form()->openTag($form); ?>
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right" id="dbshop-menu-top">
            <a href="<?php echo $this->url('navigation');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回导航列表'); ?></a>
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('保存导航'); ?></button>
            <?php echo $this->HelpUrl('navigationList'); ?>
        </h1>
    </section>

    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title"><?php echo ((isset($this->navigation) && $this->navigation->getNavigationId()) ? $this->translate('编辑导航') : $this->translate('添加导航')); ?></h3>
                    </div>

                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('导航标题'); ?><span class="must_add_value">*</span></label>
                            <div class="col-sm-6">
                                <?php echo $this->formElement($form->get('navigationTitle')); ?>
                                <?php echo $this->formElementErrors($form->get('navigationTitle'), ['class'=>'error-message']); ?>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('链接地址'); ?></label>
                            <div class="col-sm-7">
                                <?php echo $this->formElement($form->get('navigationUrl')); ?>
                                <?php echo $this->formElementErrors($form->get('navigationUrl'), ['class'=>'error-message']); ?>
                            </div>
                            <div class="col-sm-2">
                                <button type="button" onclick="addBrandUrl();" class="btn btn-primary"><?php echo $this->translate('获取商品品牌地址'); ?></button>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('导航位置'); ?></label>
                            <div class="col-sm-2">
                                <?php echo $this->formElement($form->get('navigationPlace')); ?>
                                <?php echo $this->formElementErrors($form->get('navigationPlace'), ['class'=>'error-message']); ?>
                            </div>
                            <p class="form-control-static text-blue text-sm"><?php echo $this->translate('这里的“顶部”指前台的最顶端，如需要在前台横向主菜单内显示，请选择 “中部”'); ?></p>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('商品分类'); ?></label>
                            <div class="col-sm-3">
                                <?php echo $this->formElement($form->get('goodsClassId')); ?>
                                <?php echo $this->formElementErrors($form->get('goodsClassId'), ['class'=>'error-message']); ?>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('新窗口打开'); ?></label>
                            <div class="col-sm-3">
                                <div class="checkbox">
                                    <label>
                                        <?php echo $this->formElement($form->get('newWindow')); ?><?php echo $this->translate('是'); ?>
                                        <?php echo $this->formElementErrors($form->get('newWindow'), ['class'=>'error-message']); ?>
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('排序'); ?></label>
                            <div class="col-sm-2">
                                <?php echo $this->formElement($form->get('navigationSort')); ?>
                                <?php echo $this->formElementErrors($form->get('navigationSort'), ['class'=>'error-message']); ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </section>
    <?php echo $this->form()->closeTag(); ?>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            rules: {
                navigationTitle: {
                    required: true
                }
            },
            messages: {
                navigationTitle: {
                    required: "<?php echo $this->translate('请填写导航标题!'); ?>"
                }
            }
        });
    });

    $('#goodsClassId').change(function () {
        let classUrl  = '';
        if (this.value > 0) {
            classUrl = "<?php echo $this->url('shop-class', ['action'=>'goodsList']); ?>/"+this.value;
        }
        $('#navigationUrl').val(classUrl);
    });

    function addBrandUrl() {
        $('#navigationUrl').val('');
        $('#navigationUrl').val('<?php echo $this->url('shop-brand', [], ['force_canonical' => true]); ?>');
    }
</script>